package com.bw.mvpcore.view

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.Fragment
import com.bw.mvpcore.common.ConstValue

abstract class BaseFragment:Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(getLayoutId(),container,false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        initData(savedInstanceState)
        initEvent()
    }
    /**
     * 跳转到另一个Activity
     */
    fun jumpActivity(otherActivity:Class<*>){
        startActivity(Intent(context,otherActivity))
    }
    fun jumpActivity(otherActivity:Class<*>,bundle:Bundle?){
        val intent = Intent(context,otherActivity)
        intent.putExtra(ConstValue.JUMP_ACTIVITY_PARSENTER_KEY,bundle)
        startActivity(intent)
    }
    /**
     * 吐司显示消息
     */
    fun showToast(mag:String){
        Toast.makeText(context, mag, Toast.LENGTH_SHORT).show()
    }
    /**
     * 沉浸式布局
     */
    abstract fun ClearStatBar()
    /**
     * 是否实现沉浸式
     */
    protected open  fun isClearStatBar(): Boolean{
        return true
    }
    /**
     * 初始化
     */
    abstract fun initEvent()
    /**
     * 初始化数据
     */
    abstract fun initData(savedInstanceState: Bundle?)
    /**
     * 获取布局
     */
    abstract fun getLayoutId(): Int

    override fun onStop() {
        super.onStop()
        releaseResource()
    }
    /**
     * 释放资源
     */
    abstract fun releaseResource()
}